<%@page import="com.zt.exp5.bean.Car"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
  </head>
  
  <body>
    <%	
    	Car car = (Car)session.getAttribute("car");
    
    	if(car == null){
    		car = new Car();
    		session.setAttribute("car", car);
    	}
    	
    	String action = (String)request.getParameter("action");
    	if("buy".equals(action)){
    		int id = Integer.parseInt((String)request.getParameter("id"));
    		car.buy(id, 1);
    		request.getRequestDispatcher("buy.jsp").forward(request, response);
    	}else if("showCar".equals(action)){
    		request.getRequestDispatcher("showCar.jsp").forward(request, response);
    	}else if("remove".equals(action)){
    		int id = Integer.parseInt((String)request.getParameter("id"));
    		car.remove(id, 1);
    		request.getRequestDispatcher("showCar.jsp").forward(request, response);
    	}else if("clear".equals(action)){
    		car.clear();
    		request.getRequestDispatcher("showCar.jsp").forward(request, response);
    	}
    %>
  </body>
</html>
